//package com.sinux.generality.provider.demo.aspect;
//
//import com.alibaba.fastjson.JSON;
//import com.sinux.generality.provider.demo.constants.Sets;
//import com.sinux.generality.provider.demo.entity.Optionlog;
//import com.sinux.generality.provider.demo.service.OptionlogService;
//import io.swagger.annotations.ApiOperation;
//import org.apache.commons.lang3.StringUtils;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.lang.annotation.Annotation;
//import java.util.HashMap;
//import java.util.Map;
//
//@Aspect
//@Component
//public class OptionAspect {
//    @Autowired
//    OptionlogService ols;
//    @Before("@annotation(io.swagger.annotations.ApiOperation)")
//    public void before(JoinPoint pjp){
//        Map<Object, Object> map = new HashMap<Object, Object>();
//        String name = pjp.getTarget().getClass().getCanonicalName();
//        Object[] obj = pjp.getArgs();
//        for(Object o:obj){
//            Map<Object, Object> tmpMap = (Map<Object, Object>)o;
//            map.putAll(tmpMap);
//        }
//        MethodSignature ms = (MethodSignature) pjp.getSignature();
//        ApiOperation ao = ms.getMethod().getAnnotation(ApiOperation.class);
//        // 人
//        String userName = null;
//        if(StringUtils.isEmpty(userName)){
//            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//            HttpServletRequest request = attributes.getRequest();
//            userName = request.getRemoteAddr();
//        }
//        // 时间
//        // 内容
//        System.out.println(ao.value());
//        String triggerMethod = pjp.getTarget().getClass().getName().concat(".").concat(pjp.getSignature().getName());
//
//        Optionlog ol = new Optionlog();
//        ol.setCzlx(triggerMethod);
//        ol.setCznr(JSON.toJSONString(map));
//        ol.setYhmc(userName);
//
//        // 记录操作日志
////         暂不考虑异步日志记录，比较复杂，有需要再完善
//        Sets.optionQueue.offer(ol);
//
//    }
//}
